// stores/auth.js
import { defineStore } from 'pinia'
import { ref } from 'vue'

const useAuthStore = defineStore('auth', {
  // 👇 改为 Options API 风格
  state: () => ({
    isAuthenticated: false,
    userInfo: null
  }),
  actions: {
    login(userData) {
      this.isAuthenticated = true
      this.userInfo = userData
      console.log(this.userInfo)
    },
    logout() {
      this.isAuthenticated = false
      this.userInfo = null
    }
  },
  // ✅ 正确持久化配置位置
  persist: {
    key: 'authState',
    storage: sessionStorage,
    paths: ['isAuthenticated', 'userInfo']
  }
})

export default useAuthStore